# java调用python，初步实现你自己的打卡
import requests
import sys
import io
import time
import json
import base64
import random
def signIn(dict):
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8') #改变标准输出的默认编码

    url = 'https://we.cqu.pt/api/mrdk/post_mrdk_info.php'

    headers = {
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36 Edg/85.0.564.44",
        "CONTENT_TYPE":"application/json"
    }
    # 信息替换点 
    studentId = dict["studentId"]
    name = dict["name"]
    phone = dict["phoneNumber"]
    location = dict["location"]
    # 一定随机的纬度,经度
    latitude = str(round(random.uniform(29.264,29.265),5))
    longitude = str(round(random.uniform(106.25,106.26),5))

    body = {"jbsks":"否","jbsfl":"否","jbsbs":"否","jbslt":"否","jbsyt":"否","jbsfx":"否","lxdh":phone,"xxdz":location,
    "szdq":"重庆市,重庆市,南岸区","name":name,"xh":studentId,"xb":"男","latitude":latitude,"longitude":longitude,
    "locationBig":"中国,重庆市,重庆市,渝中区","locationSmall":"重庆市渝中区人民支路96-4号","hjsfly":"否","ywjchblj":"无",
    "ywjcqzbl":"无","xjzdywqzbl":"无","twsfzc":"是","ywytdzz":"无","brsfqz":"无","brsfys":"无","jbs":"无",
    "beizhu":"备注无","sfyfy":"无","fyjtgj":"无","fyddsj":"无","sfbgsq":"无","sfjjgl":"无","jjglqssj":"无",
    "wjjglmqqx":"无","qtycqk":"无","mrdkkey":"LepVGPHN","timestamp":time.time()}
    # 这里有 2个升级的验证  一个是 openid ,一个是 mrdkkey 
    body2 = {"jbsks":"否","jbsfl":"否","jbsbs":"否","jbslt":"否","jbsyt":"否","jbsfx":"否","lxdh":phone,
    "xxdz":location,"szdq":"重庆市,重庆市,南岸区","name":name,"xh":studentId,"xb":"男",
    "openid":"oIaII0RJSeox0VnG98Rg-Fd_DV5g","latitude":latitude,"longitude":longitude,
    "locationBig":"中国,重庆市,重庆市,渝中区","locationSmall":"重庆市渝中区人民支路96-4号","hjsfly":"否",
    "ywjchblj":"无","ywjcqzbl":"无","xjzdywqzbl":"无","twsfzc":"是","ywytdzz":"无","brsfqz":"无","jbs":" 无",
    "brsfys":"无","sfyfy":"无","fyjtgj":"无","fyddsj":"无","sfbgsq":"无","sfjjgl":"无","jjglqssj":"无",
    "wjjglmqqx":"无","beizhu":"无","qtycqk":"无","mrdkkey":"XPB0oBk_","timestamp":time.time()}
    body3 = {"jbsks": "\u5426", "jbsfl": "\u5426", "jbsbs": "\u5426", "jbslt": "\u5426", "jbsyt": "\u5426", "jbsfx": "\u5426", "lxdh": "13388888888", "xxdz": "\u91cd\u5e86\u90ae\u7535\u5927\u5b66", "szdq": "\u91cd\u5e86\u5e02,\u91cd\u5e86\u5e02,\u5357\u5cb8\u533a", "name": "\u9093\u5609\u6587", "xh": "2019218888", "xb": "\u7537", "latitude": "29.2646", "longitude": "106.25785", "locationBig": "\u4e2d\u56fd,\u91cd\u5e86\u5e02,\u91cd\u5e86\u5e02,\u6e1d\u4e2d\u533a", "locationSmall": "\u91cd\u5e86\u5e02\u6e1d\u4e2d\u533a\u4eba\u6c11\u652f\u8def96-4\u53f7", "hjsfly": "\u5426", "ywjchblj": "\u65e0", "ywjcqzbl": "\u65e0", "xjzdywqzbl": "\u65e0", "twsfzc": "\u662f", "ywytdzz": "\u65e0", "brsfqz": "\u65e0", "brsfys": "\u65e0", "jbs": "\u65e0", "beizhu": "\u5907\u6ce8\u65e0", "sfyfy": "\u65e0", "fyjtgj": "\u65e0", "fyddsj": "\u65e0", "sfbgsq": "\u65e0", "sfjjgl": "\u65e0", "jjglqssj": "\u65e0", "wjjglmqqx": "\u65e0", "qtycqk": "\u65e0", "mrdkkey": "LepVGPHN", "timestamp": 1599720587.4963112}
    # json格式 因为dist字典，map格式无法使用encode方法，，我们必须将这个转化为字符串
    dataJson = json.dumps(body3) 
    # utf编码
    utf8_data=dataJson.encode('utf-8')
    # base64 加密
    base64_data=base64.b64encode(utf8_data)
    data = {"key":base64_data}


    #在发送get请求时url + 请求头head + 请求体body
    # 取消证书验证
    resp = requests.post(url, headers = headers,data = data,verify=False)

    # 打印返回的数据
    print(resp.content.decode('utf-8'))
    return resp.content.decode('utf-8')
